package pw.goyd.game.handler.imp;

import pw.goyd.game.handler.Handler;
import pw.goyd.game.logic.SetIconRequest;
import pw.goyd.game.server.Log;
import pw.goyd.game.server.LoginList;
import pw.goyd.subscribe.PlayerCustomer;

/**
 * Created by Administrator on 2016/11/3.
 */
public class SETICON extends Handler {
    @Override
    public void handle() {
        PlayerCustomer p = LoginList.getPlayer(ctx.getChannel().getId());
        if (p == null) {
            Log.getLogger().error("空指针--->ChannelID[" + ctx.getChannel().getId() + "]");
            return;
        }
        //读取icon source
        SetIconRequest setIconRequest = new SetIconRequest();
        setIconRequest.readFromBytes(request.getData());    //  read buffer
        p.setIcon_source(setIconRequest.getIcon_source());  //  cache change

        p.savePlayer();     //  设置保存用户数据
        p.sendPlayerInfo(); //  发送用户信息
        Log.getLogger().info("玩家[" + p.getNickname() + "] 设置头像[ " + setIconRequest.getIcon_source() + " ]");
    }
}
